home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / prim / page.el < prev    next >
Encoding:
Text File  |  1995-05-12  |  4.5 KB  |  146 lines

  1. ;;; page.el --- page motion commands for emacs.
  2.  
  3. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. ;;; Synched up with: FSF 19.28.
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; This code provides the page-oriented movement and selection commands
  28. ;; documented in the XEmacs Reference Manual.
  29.  
  30. ;;; Code:
  31.  
  32. (defun forward-page (&optional count)
  33.   "Move forward to page boundary.  With arg, repeat, or go back if negative.
  34. A page boundary is any line whose beginning matches the regexp
  35. `page-delimiter'."
  36.   (interactive "_p")
  37.   (or count (setq count 1))
  38.   (while (and (> count 0) (not (eobp)))
  39.     ;; In case the page-delimiter matches the null string,
  40.     ;; don't find a match without moving.
  41.     (if (bolp) (forward-char 1))
  42.     (if (re-search-forward page-delimiter nil t)
  43.     nil
  44.       (goto-char (point-max)))
  45.     (setq count (1- count)))
  46.   (while (and (< count 0) (not (bobp)))
  47.     (forward-char -1)
  48.     (if (re-search-backward page-delimiter nil t)
  49.     (goto-char (match-end 0))
  50.       (goto-char (point-min)))
  51.     (setq count (1+ count))))
  52.  
  53. (defun backward-page (&optional count)
  54.   "Move backward to page boundary.  With arg, repeat, or go fwd if negative.
  55. A page boundary is any line whose beginning matches the regexp
  56. `page-delimiter'."
  57.   (interactive "p")
  58.   (or count (setq count 1))
  59.   (forward-page (- count)))
  60.  
  61. (defun mark-page (&optional arg)
  62.   "Put mark at end of page, point at beginning.
  63. A numeric arg specifies to move forward or backward by that many pages,
  64. thus marking a page other than the one point was originally in."
  65.   (interactive "P")
  66.   (setq arg (if arg (prefix-numeric-value arg) 0))
  67.   (if (> arg 0)
  68.       (forward-page arg)
  69.     (if (< arg 0)
  70.         (forward-page (1- arg))))
  71.   (forward-page)
  72.   (push-mark nil t t)
  73.   (forward-page -1))
  74.  
  75. (defun narrow-to-page (&optional arg)
  76.   "Make text outside current page invisible.
  77. A numeric arg specifies to move forward or backward by that many pages,
  78. thus showing a page other than the one point was originally in."
  79.   (interactive "P")
  80.   (setq arg (if arg (prefix-numeric-value arg) 0))
  81.   (save-excursion
  82.     (widen)
  83.     (if (> arg 0)
  84.     (forward-page arg)
  85.       (if (< arg 0)
  86.       (forward-page (1- arg))))
  87.     ;; Find the end of the page.
  88.     (forward-page)
  89.     ;; If we stopped due to end of buffer, stay there.
  90.     ;; If we stopped after a page delimiter, put end of restriction
  91.     ;; at the beginning of that line.
  92.     (if (save-excursion
  93.       (goto-char (match-beginning 0)) ; was (beginning-of-line)
  94.       (looking-at page-delimiter))
  95.     (beginning-of-line))
  96.     (narrow-to-region (point)
  97.               (progn
  98.             ;; Find the top of the page.
  99.             (forward-page -1)
  100.             ;; If we found beginning of buffer, stay there.
  101.             ;; If extra text follows page delimiter on same line,
  102.             ;; include it.
  103.             ;; Otherwise, show text starting with following line.
  104.             (if (and (eolp) (not (bobp)))
  105.                 (forward-line 1))
  106.             (point)))))
  107.  
  108. (defun count-lines-page ()
  109.   "Report number of lines on current page, and how many are before or after point."
  110.   (interactive "_")
  111.   (save-excursion
  112.     (let ((opoint (point)) beg end
  113.       total before after)
  114.       (forward-page)
  115.       (beginning-of-line)
  116.       (or (looking-at page-delimiter)
  117.       (end-of-line))
  118.       (setq end (point))
  119.       (backward-page)
  120.       (setq beg (point))
  121.       (setq total (count-lines beg end)
  122.         before (count-lines beg opoint)
  123.         after (count-lines opoint end))
  124.       (message "Page has %d lines (%d + %d)" total before after))))
  125.  
  126. (defun what-page ()
  127.   "Print page and line number of point."
  128.   (interactive "_")
  129.   (save-restriction
  130.     (widen)
  131.     (save-excursion
  132.       (beginning-of-line)
  133.       (let ((count 1)
  134.         (opoint (point)))
  135.     (goto-char 1)
  136.     (while (re-search-forward page-delimiter opoint t)
  137.       (setq count (1+ count)))
  138.     (message "Page %d, line %d"
  139.          count
  140.          (1+ (count-lines (point) opoint)))))))
  141.  
  142. ;;; Place `provide' at end of file.
  143. (provide 'page)
  144.  
  145. ;;; page.el ends here
  146.